package com.woniuxy.util;


import com.woniuxy.enums.ResponseEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author: Apricity
 * @CreateTime: 2025-04-29
 * @Description: TODO
 * @Version: 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseData<T> {
    private Integer code;
    private String msg;
    private T data;


    /**
     * @return com.woniuxy.util.ResponseData
     * @author Arran
     * @description 修改和删除使用, 成功返回code为200
     */

    public static ResponseData ok() {
        return new ResponseData(ResponseEnum.OK.getCode(), "ok", null);
    }

    /**
     * @Author: Apricity
     * @Description: 查询使用, 成功查询获得code为200.返回查询的t对象数据
     *               系统出现异常的情况很多种，账号密码不对，库存不足，一抢 抢购旭时
     *               系统要给每种异常情况区分 可以给每种异常情况设置不同的code值
     * @CreateTime 2025/4/29 11:39
     **/
    public static <T> ResponseData ok(T t) {
        return new ResponseData(ResponseEnum.OK.getCode(), "ok", t);
    }

    public static ResponseData fail(ResponseEnum responseEnum) {
        return new ResponseData(responseEnum.getCode(), "fail", null);
    }
    public static <T> ResponseData<T> fail(int code, String msg) {
        return new ResponseData<>(code, msg, null);
    }
}
